import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
import { assetInfoFields } from '@/views/asset/asset-info/AssetInfo.data';
const { t } = useI18n('common');
import { h } from 'vue';
import { Popover } from 'ant-design-vue';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: assetInfoFields.code,
    align: 'center',
    dataIndex: 'code',
  },
  {
    title: t('createTime'),
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: t('remark'),
    align: 'center',
    dataIndex: 'notes',
  },
  {
    title: t('barCode'),
    align: 'center',
    dataIndex: 'barCode',
    width: 220,
    customRender({ text }) {
      return h(
        Popover,
        {},
        {
          default: h('img', { src: 'data:image/png;base64,' + text, style: 'height:50px; cursor: zoom-in;' }),
          content: h('img', { src: 'data:image/png;base64,' + text }),
        }
      );
    },
  },
  {
    title: t('qrCode'),
    align: 'center',
    dataIndex: 'qrCode',
    customRender({ text }) {
      return h(
        Popover,
        {},
        {
          default: h('img', { src: 'data:image/png;base64,' + text, style: 'height:50px; cursor: zoom-in;' }),
          content: h('img', { src: 'data:image/png;base64,' + text }),
        }
      );
    },
  },

  {
    title: assetInfoFields.name,
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: assetInfoFields.cartegory,
    align: 'center',
    dataIndex: 'cartegoryId',
    customRender: ({ text }) => {
      return render.renderDict(text, 'asset_category');
    },
  },
  {
    title: assetInfoFields.useState,
    align: 'center',
    dataIndex: 'useState',
    customRender: ({ text }) => {
      return render.renderDict(text, 'useState');
    },
  },
  {
    title: assetInfoFields.position,
    align: 'center',
    dataIndex: 'positionId_dictText',
  },
  {
    title: assetInfoFields.rfid,
    align: 'center',
    dataIndex: 'rfid',
  },
  {
    title: assetInfoFields.user,
    align: 'center',
    dataIndex: 'userId_dictText',
  },
  {
    title: assetInfoFields.custodyDepartment,
    align: 'center',
    dataIndex: 'custodyDepartmentId_dictText',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: assetInfoFields.code,
    field: 'code',
    component: 'Input',
  },
  {
    label: t('createTime'),
    field: 'createTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: t('remark'),
    field: 'notes',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
